<!DOCTYPE html>
<html lang="en-US">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>ComplexReflect 静态类 | Math Complex</title>
    <meta name="description" content="简单易用的JavaScript复数扩展数学库">

    
    <link rel="preload" href="/math-complex/assets/css/0.styles.dc9a62cc.css" as="style"><link rel="preload" href="/math-complex/assets/js/app.a7e80bc5.js" as="script"><link rel="preload" href="/math-complex/assets/js/2.b96ecc85.js" as="script"><link rel="preload" href="/math-complex/assets/js/7.30d57aa9.js" as="script"><link rel="prefetch" href="/math-complex/assets/js/10.e877db03.js"><link rel="prefetch" href="/math-complex/assets/js/11.aa6e74d4.js"><link rel="prefetch" href="/math-complex/assets/js/12.ef27bf30.js"><link rel="prefetch" href="/math-complex/assets/js/13.6d5e4273.js"><link rel="prefetch" href="/math-complex/assets/js/3.3a2d5ce2.js"><link rel="prefetch" href="/math-complex/assets/js/4.5f9aa696.js"><link rel="prefetch" href="/math-complex/assets/js/5.8bdadb5e.js"><link rel="prefetch" href="/math-complex/assets/js/6.0954e40b.js"><link rel="prefetch" href="/math-complex/assets/js/8.6149196e.js"><link rel="prefetch" href="/math-complex/assets/js/9.6ecdb287.js">
    <link rel="stylesheet" href="/math-complex/assets/css/0.styles.dc9a62cc.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/math-complex/" class="home-link router-link-active"><!----> <span class="site-name">Math Complex</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/math-complex/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/math-complex/guide/" class="nav-link">
  入门指南
</a></div><div class="nav-item"><a href="/math-complex/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="/math-complex/appendix/" class="nav-link">
  附录
</a></div><div class="nav-item"><a href="https://github.com/shawroger/math-complex" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/math-complex/" class="nav-link">
  主页
</a></div><div class="nav-item"><a href="/math-complex/guide/" class="nav-link">
  入门指南
</a></div><div class="nav-item"><a href="/math-complex/API/" class="nav-link router-link-active">
  API
</a></div><div class="nav-item"><a href="/math-complex/appendix/" class="nav-link">
  附录
</a></div><div class="nav-item"><a href="https://github.com/shawroger/math-complex" target="_blank" rel="noopener noreferrer" class="nav-link external">
  Github
  <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group collapsable depth-0"><p class="sidebar-heading open"><span>API</span> <span class="arrow down"></span></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/math-complex/API/" class="sidebar-link">全局对象</a></li><li><a href="/math-complex/API/complex-number.html" class="sidebar-link">ComplexNumber 类</a></li><li><a href="/math-complex/API/complex-reflect.html" class="active sidebar-link">ComplexReflect 静态类</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#abs" class="sidebar-link">abs</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#abssquare" class="sidebar-link">absSquare</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#add" class="sidebar-link">add</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#angle" class="sidebar-link">angle</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#contrary" class="sidebar-link">contrary</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#fromangle" class="sidebar-link">fromAngle</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#imagine" class="sidebar-link">imagine</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#iscomplex" class="sidebar-link">isComplex</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#mult" class="sidebar-link">mult</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#pow" class="sidebar-link">pow</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#random" class="sidebar-link">random</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#realize" class="sidebar-link">realize</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#tocomplex" class="sidebar-link">toComplex</a></li><li class="sidebar-sub-header"><a href="/math-complex/API/complex-reflect.html#tryrealize" class="sidebar-link">tryRealize</a></li></ul></li></ul></section></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="complexreflect-静态类"><a href="#complexreflect-静态类" class="header-anchor">#</a> ComplexReflect 静态类</h1> <p><strong>ComplexReflect</strong> 是本库的函数方法类，使用本类的静态方法可以更直接地操作 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象数据，并且 <strong>ComplexReflect</strong> 类中的所有方法都是静态方法，并且对原生 <strong>number</strong> 对象也有良好兼容性。</p> <h2 id="abs"><a href="#abs" class="header-anchor">#</a> abs</h2> <p><strong>abs</strong> 返回一个 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象的模长。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">abs</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> x <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> <span class="token comment">// 原生number对象</span>
<span class="token keyword">const</span> z <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ComplexNumber对象</span>

ComplexReflect<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">2</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">abs</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">5</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="abssquare"><a href="#abssquare" class="header-anchor">#</a> absSquare</h2> <p><strong>absSquare</strong> 返回一个 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象模长的平方。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">absSquare</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> x <span class="token operator">=</span> <span class="token number">2</span><span class="token punctuation">;</span> <span class="token comment">// 原生number对象</span>
<span class="token keyword">const</span> z <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// ComplexNumber对象</span>

ComplexReflect<span class="token punctuation">.</span><span class="token function">absSquare</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">4</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">absSquare</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">25</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="add"><a href="#add" class="header-anchor">#</a> add</h2> <p><strong>add</strong> 定义了 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象的加法运算，并且支持多个参数（至少2个）。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">add</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">,</span> <span class="token operator">...</span>args<span class="token operator">:</span> <span class="token builtin">Array</span><span class="token operator">&lt;</span><span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token operator">&gt;</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword">const</span> z3 <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> z4 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> z2<span class="token punctuation">,</span> z3<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// z4 = z1 + z2 + z3</span>
</code></pre></div><h2 id="angle"><a href="#angle" class="header-anchor">#</a> angle</h2> <p><strong>angle</strong> 返回 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象的辐角主值（原生 <strong>number</strong> 对象即为0）。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">angle</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">1</span><span class="token punctuation">,</span> <span class="token number">1</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">angle</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span> <span class="token operator">===</span> Math<span class="token punctuation">.</span><span class="token constant">PI</span> <span class="token operator">/</span> <span class="token number">4</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">angle</span><span class="token punctuation">(</span><span class="token number">1234</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="contrary"><a href="#contrary" class="header-anchor">#</a> contrary</h2> <p><strong>contrary</strong> 返回一个 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象的相反数。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">contrary</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> <span class="token comment">// z1 = 3 + 4i</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">contrary</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">.</span>real <span class="token operator">===</span> <span class="token operator">-</span><span class="token number">3</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">contrary</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">.</span>imaginary <span class="token operator">===</span> <span class="token operator">-</span><span class="token number">4</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">contrary</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token operator">-</span><span class="token number">5</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="fromangle"><a href="#fromangle" class="header-anchor">#</a> fromAngle</h2> <p><strong>fromAngle</strong> 是另一个 <strong>ComplexNumber</strong> 对象的构造器，<strong>fromAngle</strong> 接收的参数是复数的模长和幅角主值。</p> <p>参见 <a href="/math-complex/API/complex-number.html#fromangle">fromAngle</a>。</p> <h2 id="imagine"><a href="#imagine" class="header-anchor">#</a> imagine</h2> <p><strong>imagine</strong> 返回一个 <strong>ComplexNumber</strong> 的虚部， 或参数为原生 <strong>number</strong> 对象，则返回 0。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">imagine</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">.</span>real <span class="token operator">===</span> <span class="token number">4</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="iscomplex"><a href="#iscomplex" class="header-anchor">#</a> isComplex</h2> <p><strong>isComplex</strong> 用来判断一个对象是不是 <strong>ComplexNumber</strong> 构造的对象。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">isComplex</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">any</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">boolean</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span><span class="token punctuation">.</span>real <span class="token operator">===</span> <span class="token number">4</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="mult"><a href="#mult" class="header-anchor">#</a> mult</h2> <p><strong>add</strong> 定义了 <strong>ComplexNumber</strong> 或原生 <strong>number</strong> 对象的乘法法运算，并且支持多个参数（至少2个）。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">mult</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">,</span> <span class="token operator">...</span>args<span class="token operator">:</span> <span class="token builtin">Array</span><span class="token operator">&lt;</span><span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token operator">&gt;</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">,</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> z3 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">mult</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> <span class="token number">5</span> <span class="token punctuation">,</span>z2<span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token comment">// z3 = z1 * 5 *z2</span>
</code></pre></div><h2 id="pow"><a href="#pow" class="header-anchor">#</a> pow</h2> <p><strong>pow</strong> 定义了 <strong>ComplexNumber</strong> 的乘方运算。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">pow</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">,</span> power<span class="token operator">:</span> <span class="token builtin">number</span><span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li><p>幂可为 0、正整数、负整数和分数</p></li> <li><p>幂为 0 时，返回值为 1</p></li> <li><p>幂为正整数时，返回值为复数自乘 n 次的结果 （参见 <a href="/math-complex/API/complex-number.html#pow">pow 方法</a>）</p></li> <li><p>幂为负整数时，返回值为复数自乘 n 次的结果的倒数 （参见 <a href="/math-complex/API/complex-number.html#recip">recip 方法</a>）</p></li> <li><p>幂为分数时，返回值为复数开 1 / n 次方的结果 （参见 <a href="/math-complex/API/complex-number.html#sqrt">sqrt 方法</a>）</p></li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword">const</span> z2 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> <span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> z3 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> <span class="token operator">-</span><span class="token number">3</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> z4 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">pow</span><span class="token punctuation">(</span>z1<span class="token punctuation">,</span> <span class="token number">0.5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><h2 id="random"><a href="#random" class="header-anchor">#</a> random</h2> <p><strong>random</strong> 返回一个随机的 <strong>ComplexNumber</strong> 的对象。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token operator">:</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre></div><ul><li>实际上，<strong>random()</strong> 方法就是返回实部虚部都为 <strong>Math.random()</strong> 的对象。</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">class</span> <span class="token class-name">ComplexReflect</span> <span class="token punctuation">{</span>
    <span class="token comment">// ...</span>
    <span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token keyword">new</span> <span class="token class-name">ComplexNumber</span><span class="token punctuation">(</span>Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> Math<span class="token punctuation">.</span><span class="token function">random</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre></div><h2 id="realize"><a href="#realize" class="header-anchor">#</a> realize</h2> <p><strong>realize</strong> 返回一个 <strong>ComplexNumber</strong> 的虚部，或参数为原生 <strong>number</strong> 对象，则返回自身。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">realize</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z1 <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">3</span><span class="token punctuation">,</span> <span class="token number">4</span><span class="token punctuation">)</span><span class="token punctuation">;</span> 
<span class="token keyword">const</span> z2 <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>

ComplexReflect<span class="token punctuation">.</span><span class="token function">realize</span><span class="token punctuation">(</span>z1<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">3</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">realize</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">5</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="tocomplex"><a href="#tocomplex" class="header-anchor">#</a> toComplex</h2> <p><strong>toComplex</strong> 可以将原生 <strong>number</strong> 对象转化为虚部为 0 的 <strong>ComplexNumber</strong> 对象，如果参数本身已经是 <strong>ComplexNumber</strong> 对象，则直接返回自身。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">toComplex</span><span class="token punctuation">(</span>num<span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> x <span class="token operator">=</span> <span class="token number">5</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> z <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">toComplex</span><span class="token punctuation">(</span>x<span class="token punctuation">)</span><span class="token punctuation">;</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">realize</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">5</span> <span class="token comment">// true</span>
ComplexReflect<span class="token punctuation">.</span><span class="token function">imagine</span><span class="token punctuation">(</span>z2<span class="token punctuation">)</span> <span class="token operator">===</span> <span class="token number">0</span> <span class="token comment">// true</span>
</code></pre></div><h2 id="tryrealize"><a href="#tryrealize" class="header-anchor">#</a> tryRealize</h2> <p>与 <strong>toComplex</strong> 相反，<strong>tryRealize</strong> 可以将虚部为 0 的 <strong>ComplexNumber</strong> 对象转化为原生 <strong>number</strong> 对象，如果<strong>ComplexNumber</strong> 对象参数的虚部不为 0 ，则直接返回自身。</p> <ul><li>类型定义</li></ul> <div class="language-ts extra-class"><pre class="language-ts"><code><span class="token keyword">static</span> <span class="token function">tryRealize</span><span class="token punctuation">(</span>complex<span class="token operator">:</span> ComplexNumber<span class="token punctuation">)</span><span class="token operator">:</span> <span class="token builtin">number</span> <span class="token operator">|</span> ComplexNumber<span class="token punctuation">;</span>
</code></pre></div><ul><li>示例</li></ul> <div class="language-javascript extra-class"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span> define<span class="token punctuation">,</span> ComplexReflect <span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">&quot;math-complex&quot;</span><span class="token punctuation">;</span>

<span class="token keyword">const</span> z <span class="token operator">=</span> <span class="token function">define</span><span class="token punctuation">(</span><span class="token number">5</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token keyword">const</span> x <span class="token operator">=</span> ComplexReflect<span class="token punctuation">.</span><span class="token function">tryRealize</span><span class="token punctuation">(</span>z<span class="token punctuation">)</span><span class="token punctuation">;</span>
x <span class="token operator">===</span> <span class="token number">5</span> <span class="token comment">// true</span>
</code></pre></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/math-complex/API/complex-number.html" class="prev">
        ComplexNumber 类
      </a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/math-complex/assets/js/app.a7e80bc5.js" defer></script><script src="/math-complex/assets/js/2.b96ecc85.js" defer></script><script src="/math-complex/assets/js/7.30d57aa9.js" defer></script>
  </body>
</html>
